package net.hcpme.activity;

import net.hcpme.activity.http.HttpDownloader;
import net.hcpme.activity.view.ZoomableImageView;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class ShowWebImageActivity extends Activity {
    private TextView imageTextView = null;
    private String imagePath = null;
    private ZoomableImageView imageView = null;
    private Bitmap img;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_webimage);
        this.imagePath = getIntent().getStringExtra("image");

        this.imageTextView = (TextView) findViewById(R.id.show_webimage_imagepath_textview);
        imageTextView.setText(this.imagePath);
        imageView = (ZoomableImageView) findViewById(R.id.show_webimage_imageview);
        loadImageFromUrl();
    }

    private void loadImageFromUrl() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                img = HttpDownloader.getHttpBitmap(imagePath);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        imageView.setImageBitmap(img);
                    }
                });
            }
        }).start();
    }

}